var gulp = require('gulp');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');

var paths = {
  sass : ['./www/lib/tab-frame/*.scss'],    
  plugin : ['./www/lib/tab-frame/*.js'],		
  css : ['./www/css/style.css'],
  js :  ['./www/js/*.js']
};

var bower_components_path = './bower_components/**';
var lib_path = './www/lib';

gulp.task('default', ['sass']);

//copy bower_components to www/lib
gulp.task('makeDependcy',function(){
  gulp.src(bower_components_path)
    .pipe(gulp.dest(lib_path));
});

gulp.task('sass', function(done) {
  gulp.src(['./www/lib/tab-frame/zhx-tabFrame.style.scss'])
    .pipe(sass())
    .on('error', sass.logError)
    .pipe(gulp.dest('./www/lib/tab-frame/'))
    .pipe(minifyCss({
      keepSpecialComments: 0
    }))
    .pipe(rename({ extname: '.min.css' }))
    .pipe(gulp.dest('./www/lib/tab-frame/dist/'))
    .on('end', done);
});

gulp.task('packageFrame',function(){
	gulp.src('./www/lib/tab-frame/*.js')
		.pipe( uglify() )
		.pipe( rename({ extname: '.min.js' }) )
		.pipe( gulp.dest('./www/lib/tab-frame/dist') )
})
//make js concat to one js
// gulp.task('script', function(){
//   gulp.src( './www/js/*.js' )
//       .pipe( concat('zhx-we-app.js') )
//       .pipe( gulp.dest('./www/js/dest') )
//       .pipe( uglify() )
//       .pipe( rename({ extname: '.min.js' } ) )
//       .pipe( gulp.dest('./www/js/dest') );
// });

gulp.task('watch', function() {
  gulp.watch(paths.sass, ['sass']);
  gulp.watch(paths.plugin, ['packageFrame']);
  // gulp.watch(paths.js, ['script']);
  // gulp.watch(bower_components_path, ['makeDependcy']);
});
